﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace Infratructure
{
    public class Repository <T>:IRepository<T> where T:class
    {
        MyDBcontext DB;

        public Repository(MyDBcontext dB)
        {
            DB = dB;
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="t">参数</param>
        /// <returns>影响行数</returns>
        public async Task<int> Addway(T t)
        {
            DB.Set<T>().AddAsync(t);
            return await DB.SaveChangesAsync();
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="t">参数</param>
        /// <returns>影响行数</returns>
        public async Task<int> Updateway(T t)
        {
            DB.Set<T>().Update(t);
            return await DB.SaveChangesAsync();
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="t">参数</param>
        /// <returns>数据</returns>
        public async Task<T> GetValue(long Id)
        {
            return await DB.Set<T>().FindAsync(Id);
        }
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns>查询条件</returns>
        public IQueryable<T> GetAll()
        {
          
            return DB.Set<T>();  
        }

    }
}
